package org.imdm.portal.loadchecker.telnet;

import org.imdm.portal.loadchecker.ui.LoadInfo;

public class ReadVersionCommand extends Command{

  public ReadVersionCommand(TelnetClientAdvance telnet) {
    super(telnet);
  }

  public String execute()  throws TelnetException{
    String version = LoadInfo._UNKNOWN;
    String cd = sendCommand("cd /opt/MagellanNMS");
	if ( cd.indexOf("No such file or directory") >= 0 )
		return version;
    String versionInfo = sendCommand("ls -al");

    String mark = "lib -> /view/";
    int index = versionInfo.indexOf(mark);
    if(index==-1){
    	mark = "lib -> loads/";
    	index = versionInfo.indexOf(mark);
    	if(index==-1)
    		return version;
    }
    int endIndex = versionInfo.indexOf("/",index+mark.length()+1);
    if(endIndex==-1){
    	return version;
    }

    version = versionInfo.substring(index+mark.length(),endIndex);

    return version;
  }

}
